<?php
//error_reporting(ALL); 
define('IN_ADAGPS', TRUE); 

include_once('adagps.com/cfg.php');
include_once(CORE_PATH.'database/commonDB.php'); 
if(!ConnectDB())
{
    if( $_REQUEST['xajax']==null){
        echo $objDbSelect->ErrorMsg(), '<br>';
    }       
    if($arrConfig['debug'] === true)
    {
        Die(CONNECT_DB_ERR);
    }else{
        $_POST['xajax']='ajxLogout';
    }
    Die(CONNECT_DB_ERR);
}
if(!isset($_SESSION['current']['user_name'])){
  header('Location: index.php'); 
  exit(); 
}
//global $objDbSelect;

$objXajax->registerFunction('loadhelpById');
$objXajax->processRequests();
$tplXajaxScript = $tplXajaxScript.$objXajax->getJavascript('adagps.com/scripts/xajax');    

//  echo  $helpIndex;  

$tablemain = 'tbl_main_menu'; 
$tablesub = 'tbl_menu';
if($_SESSION['current']['power_type_id']==POWER_CUSTOMER||$_SESSION['current']['power_type_id']==POWER_SUB_CUSTOMER){
  $tablemain = 'tbl_main_menu_cus'; 
  $tablesub = 'tbl_menu_cus';  
}
 
$sql = "SELECT t.name_vi as name_sub,t.id, main_menu_id,m.name_vi name_main
FROM $tablesub t join $tablemain as m on t.main_menu_id = m.id and t.active=1 and m.active=1
order by m.ordershow,t.ordershow,t.name_vi" ;
$arr = $objDbSelect->GetArray($sql);
$count =count($arr);
$arrNew=array();
$temp='';
$index_new =-1;
for($i=0;$i<$count;$i++){
  if($temp!=$arr[$i]['main_menu_id']){
    $index_new++;
    $arrNew[$index_new]['name']=$arr[$i]['name_main'];  
    $arrNew[$index_new]['matches'][]=array('name'=>$arr[$i]['name_sub'],'id'=>$arr[$i]['id']); 
    $temp = $arr[$i]['main_menu_id'];
  }else{
    $arrNew[$index_new]['matches'][]=array('name'=>$arr[$i]['name_sub'],'id'=>$arr[$i]['id']);  
  }  
} 

$TBS = new clsTinyButStrong;
$TBS->LoadTemplate('help.html');

$helpIndex = isset($_GET['helpIndex'])? $_GET['helpIndex']:0;
/*if(!is_int($helpIndex))
$helpIndex=0; */
//echo $helpIndex;
// Subblock with a dynamic query
$TBS->MergeBlock('mb','array','arrNew');
$TBS->MergeBlock('sb','array','arrNew[%p1%][matches]');

  
$TBS->Show();
CloseDB();

function loadhelpById($id){
   global $objDbSelect;
   is_int($id)?$id:0;
   $objResponse = new xajaxResponse();  
   
    $tablesub = 'tbl_menu';
    if($_SESSION['current']['power_type_id']==POWER_CUSTOMER||$_SESSION['current']['power_type_id']==POWER_SUB_CUSTOMER){
    $tablesub = 'tbl_menu_cus';  
    }
  
   $sql = "select help_content,help_status from $tablesub where id = '$id' and active = 1 ";
   $arr = $objDbSelect->GetArray($sql);
    $content ='';
   if(is_array($arr)&&count($arr)){
      $content = htmlspecialchars_decode(trim($arr[0]['help_content'])); 
      $help_status = trim($arr[0]['help_status']); 
      if($content==''||$help_status==1){
          $content = 'Đang cập nhật...';
      }
   }else{
       $TBS = new clsTinyButStrong;
     $TBS->LoadTemplate('help_page_first.html');
     $TBS->Show(TBS_NOTHING);
     $content = $TBS->Source;
       
   } 
   $objResponse->addAssign('td_helpcontent', 'innerHTML', $content);   
   return $objResponse->getXML();
}
?>
                                         
